/************************************
 * Package: RGcpp					*
 * Authors: Rui Eduardo Gouveia Gil	*
 * Date: 2010						*
 ************************************/
#ifndef __RGCPP_FILELOCK_H_
#define __RGCPP_FILELOCK_H_

#include <string>

#include "rgcpp/exceptions/RuntimeException.h"
#ifndef _WIN32
namespace rgcpp
{

/* Operations for the `flock' call.  */
enum EFileLockMode
{
	LOCK_NONE=8,		/* Unlock.  */
	LOCK_SHARE=1,		/* Shared lock.  */
	LOCK_EXCLUSIVE=2	/* Exclusive lock.  */
};

class FileLock
{
	private:
		int lockFd;
		EFileLockMode mode;
		std::string filePath;

	public:
		FileLock(std::string aFilePath, EFileLockMode aMode=LOCK_SHARE);
		~FileLock();

	private:
		void lock();
		void unlock();
};

}

#endif
#endif
